package com.music.controller;

import com.github.pagehelper.PageInfo;
import com.music.dto.Result;
import com.music.entity.UserLikeVo;
import com.music.service.UserLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname UserLikeController
 * @Description TODO
 * @Version 1.0.0
 * @Date 2022/7/4 17:20
 * @Created by Administrator
 */
@RestController
@RequestMapping("/userLike")
public class UserLikeController {

    @Autowired
    private UserLikeService userLikeService;

    @GetMapping
    public Result getUserLikeByType(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam Integer userLikeType, String userId) {
        Result result = new Result();
        PageInfo pageInfo = userLikeService.getUserLikeByCondition(pageNum, pageSize, userLikeType, userId);
        if (!pageInfo.getList().isEmpty()) {
            result.ok(pageInfo);
        } else {
            result.fail(0, "没有相关数据");
        }
        return result;
    }

    @GetMapping("/count")
    public Result countUserLike(@RequestParam String userId) {
        Result result = new Result();
        List<UserLikeVo> userLikeVoList = userLikeService.countUserLike(userId);
        if (userLikeVoList.isEmpty()) {
            result.fail(0, "没有相关数据");
        } else {
            result.ok(userLikeVoList);
        }
        return result;
    }
}
